<?php

/**
 * @name RouterController.php
 */
class RouterController extends AppController
{
    # Controller name

    var $name = 'Router';
    # set the model to use
    var $uses = array('User','MenuGroup');
    # Set the layout to use
    public function beforeFilter($param_array = null)
    {
        parent::beforeFilter($validate_access_control = false);
    }

    function index()
    {
        $authUser = $user_auth = $this->Auth->user();
        if($authUser){
            $this->redirect(array('controller' => 'Dashboard', 'action' => 'index'));
        }
        else{
            $this->redirect(array('controller' => 'Users', 'action' => 'logout'));
        }
       /* $group_id = $this->Auth->user('group_id');
        $data = $this->MenuGroup->getGroupMenus($group_id);

        if (!empty($data)) {
            foreach($data as $um){
                if(isset($um['sub'])){
                    foreach($um['sub'] as $inner_um){
                        $this->redirect(array('controller' => $inner_um['controller'], 'action' => $inner_um['action']));
                    }
                }
                else{
                    $this->redirect(array('controller' => $um['controller'], 'action' => $um['action']));
                }
            }
        } else { //This will prevent users without purpose
            //$this->redirect(array('controller' => 'Users', 'action' => 'logout'));
        }*/
    }
}